/*#include <iostream>
#include <vector>
using namespace std;
int main()
{
	vector<int> v;
	size_t cap = v.capacity();
	cout <<"initital capacity:"<< cap << endl;
	for (int i = 0; i < 100; i++)
	{
		v.push_back(i);
		if (cap != v.capacity())
		{
			cap = v.capacity();
			cout << "capacity changed:" << cap << endl;
		}
	} 
	return 0;
}*/

/*#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int a[] = { 1, 2, 3, 4 };
	vector<int> v(a, a + sizeof(a) / sizeof(int));
	// 使用find查找3所在位置的iterator
	vector<int>::iterator pos = find(v.begin(), v.end(), 3);
	// 删除pos位置的数据，导致pos迭代器失效。
	v.erase(pos);
	cout << *pos << endl; // 此处会导致非法访问
	return 0;
}*/


#include <iostream>
#include <vector>
using namespace std;
int main()
{
	vector<int> v{1,2,3,4};
	//删除偶数
	vector<int>::iterator it = v.begin();
	while (it != v.end())
	{
		if ((*it) % 2 == 0)
		{
			v.erase(it);
		}
		it++;
	}
	
	for (auto& e : v)
	{
		cout << e << " ";
	}
	cout << endl;

	return 0;
}
